package cn.sinata.wanglin.village.activity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import com.facebook.drawee.view.SimpleDraweeView;
import com.xilada.xldutils.activitys.RecyclerListActivity;
import com.xilada.xldutils.adapter.BaseRecyclerAdapter;
import com.xilada.xldutils.adapter.util.ViewHolder;
import java.util.ArrayList;
import cn.sinata.wanglin.R;
import cn.sinata.wanglin.model.SignupUserBean;
import cn.sinata.wanglin.net.HttpManager;
import cn.sinata.wanglin.net.model.util.ResultDataSubscriber;
import cn.sinata.wanglin.utils.RelativeDateFormat;

public class SignupUserListActivity extends RecyclerListActivity {
    private String activityID=null;
    private BaseRecyclerAdapter adapter;
    private ArrayList<SignupUserBean> mSignupUserBeans=new ArrayList<SignupUserBean>();
    @Override
    protected RecyclerView.Adapter setAdapter() {
        adapter=new BaseRecyclerAdapter<SignupUserBean>(mSignupUserBeans, R.layout.item_userlist_vertical) {
            @Override
            public void onBind(final int position, final SignupUserBean data, ViewHolder holder) {
                ((SimpleDraweeView) holder.bind(R.id.iv_showphoto)).setImageURI(data.getHeadUrl());
                holder.setText(R.id.tv_username,data.getNickName());
                if(!TextUtils.isEmpty(data.getNickName())){
                    holder.setText(R.id.tv_username,data.getNickName());
                }else{
                    holder.setText(R.id.tv_username,"开心网邻用户");
                }
                if(!TextUtils.isEmpty(""+data.getCreateDate())){
                    holder.setText(R.id.tv_time, RelativeDateFormat.format(""+data.getCreateDate()));
                }else{
                    holder.setText(R.id.tv_time,"暂无时间");
                }
            }
        };
        return adapter;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("报名");
        activityID=getIntent().getStringExtra("activityID");
        getData();
    }
private  void getData(){
    HttpManager.getSignupInfo(activityID).subscribe(new ResultDataSubscriber<ArrayList<SignupUserBean>>(this) {
        @Override
        public void onSuccess(String msg, ArrayList<SignupUserBean> signupUserBeen) {
            if(signupUserBeen!=null&&signupUserBeen.size()!=0){
                mSignupUserBeans.clear();
                mSignupUserBeans.addAll(signupUserBeen);
                adapter.notifyDataSetChanged();
                setTitle("报名("+signupUserBeen.size()+")");
            }else{
                setTitle("报名(0)");
            }
        }
    });
}

    @Override
    protected void pullDownRefresh() {
        super.pullDownRefresh();
        getData();
    }
}
